#include<bits/stdc++.h>
using namespace std;
int main(){
	int n, x;
	int ans = 0;
	cin>>n;
	priority_queue<int, vector<int>, greater<int>> q;
	while(n--){
		cin>>x;
		q.push(x);
	}
	while(q.size() != 1){
		int t1 = q.top();
		q.pop();
		int t2 = q.top();
		q.pop();
		q.push(t1+t2);
		ans += t1+t2;
	}
	cout<<ans;
	return 0;
}
